import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/index/index/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard', affix: true },
      },
      {
        path: 'infomation',
        name: 'Infomation',
        component: () => import('@/views/index/index/infomation/index'),
        meta: { title: '中废通资讯', icon: 'dashboard' },
      },
      {
        path: 'infomationDetail',
        name: 'InfomationDetail',
        component: () => import('@/views/index/index/infomation/detail'),
        meta: { title: '资讯详情', icon: 'dashboard' },
      },
    ],
  },
]

export const asyncRoutes = [
  {
    path: '/system',
    component: Layout,
    meta: { title: '系统管理' },
    redirect: '/system/account',
    children: [
      {
        path: 'account',
        component: () => import('@/views/systemManagement/system/account/index'), // Parent router-view
        name: 'Account',
        meta: { title: '员工管理' },
      },
      {
        path: 'role',
        component: () => import('@/views/systemManagement/system/role/index'),
        name: 'Role',
        meta: { title: '角色管理' },
      },
      {
        path: 'menu',
        component: () => import('@/views/systemManagement/system/menu/index'),
        name: 'Menu',
        meta: { title: '菜单管理' },
      },
      {
        path: 'department',
        component: () => import('@/views/systemManagement/system/department/index'),
        name: 'Department',
        meta: { title: '部门管理' },
      },
    ],
  },
  {
    path: '/assetsPublic',
    component: Layout,
    meta: {
      title: '资产公开',
      icon: 'nested',
    },
    redirect: '/assetsPublic/assetBoard',
    children: [
      {
        path: 'assetBoard',
        component: () => import('@/views/infoManagement/assetsPublic/assetBoard/index'), // Parent router-view
        name: 'AssetBoard',
        meta: { title: '资产看板' },
      },
      {
        path: 'assetManagement',
        component: () => import('@/views/infoManagement/assetsPublic/assetManagement/index'), // Parent router-view
        name: 'AssetManagement',
        meta: { title: '资产管理' },
      },
      {
        path: 'assetPublish',
        component: () => import('@/views/infoManagement/assetsPublic/assetPublish/index'), // Parent router-view
        name: 'AssetPublish',
        meta: { title: '发布' },
      },
      {
        path: 'lockRecord',
        component: () => import('@/views/infoManagement/assetsPublic/lockRecord/index'), // Parent router-view
        name: 'LockRecord',
        meta: { title: '锁定记录' },
      },
      {
        path: 'assetsCompetitorStatistics',
        component: () => import('@/views/infoManagement/assetsPublic/competitorStatistics/index'), // Parent router-view
        name: 'AssetsCompetitorStatistics',
        meta: { title: '竞品对比统计' },
      },
      {
        path: 'assetsCompetitorManagement',
        component: () => import('@/views/infoManagement/assetsPublic/competitorManagement/index'), // Parent router-view
        name: 'AssetsCompetitorManagement',
        meta: { title: '竞品对比处理' },
      },
      {
        path: 'assetIdentifyImage',
        component: () => import('@/views/infoManagement/assetsPublic/assetIdentifyImage/index'), // Parent router-view
        name: 'AssetIdentifyImage',
        meta: { title: '资产鉴图' },
      },
    ],
  },
  {
    path: '/assetsAlone',
    component: Layout,
    meta: {
      title: '资产独享',
      icon: 'nested',
    },
    redirect: '/assetsAlone/aloneBoard',
    children: [
      {
        path: 'aloneBoard',
        component: () => import('@/views/infoManagement/assetsAlone/aloneBoard/index'), // Parent router-view
        name: 'AloneBoard',
        meta: { title: '独享看板' },
      },
      {
        path: 'aloneManagement',
        component: () => import('@/views/infoManagement/assetsAlone/aloneManagement/index'), // Parent router-view
        name: 'AloneManagement',
        meta: { title: '独享管理' },
      },
      {
        path: 'aloneDetail',
        component: () => import('@/views/infoManagement/assetsAlone/aloneManagement/detail'), // Parent router-view
        name: 'AloneDetail',
        meta: { title: '独享详情', subRoute: true, parentPath: 'aloneManagement' },
      },
      {
        path: 'alonePublish',
        component: () => import('@/views/infoManagement/assetsAlone/alonePublish/index'), // Parent router-view
        name: 'AlonePublish',
        meta: { title: '发布' },
      },
    ],
  },
  {
    path: '/biddingNotice',
    component: Layout,
    meta: {
      title: '招标公告',
      icon: 'nested',
    },
    redirect: '/biddingNotice/noticeBoard',
    children: [
      {
        path: 'noticeBoard',
        component: () => import('@/views/infoManagement/biddingNotice/noticeBoard/index'), // Parent router-view
        name: 'NoticeBoard',
        meta: { title: '公告看板' },
      },
      {
        path: 'noticeManagement',
        component: () => import('@/views/infoManagement/biddingNotice/noticeManagement/index'), // Parent router-view
        name: 'NoticeManagement',
        meta: { title: '公告管理' },
      },
      {
        path: 'noticeDetail',
        component: () => import('@/views/infoManagement/biddingNotice/noticeManagement/detail'), // Parent router-view
        name: 'NoticeDetail',
        meta: { title: '公告详情', subRoute: true, parentPath: 'noticeManagement' },
      },
      {
        path: 'noticePublish',
        component: () => import('@/views/infoManagement/biddingNotice/noticePublish/index'), // Parent router-view
        name: 'NoticePublish',
        meta: { title: '公告添加' },
      },
      {
        path: 'innerNoticeManagement',
        component: () => import('@/views/infoManagement/biddingNotice/innerNoticeManagement/index'), // Parent router-view
        name: 'InnerNoticeManagement',
        meta: { title: '内部公告管理' },
      },
      {
        path: 'innerNoticePublish',
        component: () => import('@/views/infoManagement/biddingNotice/innerNoticePublish/index'), // Parent router-view
        name: 'InnerNoticePublish',
        meta: { title: '内部公告添加', subRoute: true, parentPath: 'innerNoticeManagement' },
      },
      {
        path: 'innerNoticeDetail',
        component: () => import('@/views/infoManagement/biddingNotice/innerNoticeManagement/detail'), // Parent router-view
        name: 'InnerNoticeDetail',
        meta: { title: '内部公告详情', subRoute: true, parentPath: 'innerNoticeManagement' },
      },
      {
        path: 'noticeStatistics',
        component: () => import('@/views/infoManagement/biddingNotice/noticeStatistics/index'), // Parent router-view
        name: 'NoticeStatistics',
        meta: { title: '公告统计' },
      },
      {
        path: 'innerNoticeStatistics',
        component: () => import('@/views/infoManagement/biddingNotice/innerNoticeStatistics/index'), // Parent router-view
        name: 'InnerNoticeStatistics',
        meta: { title: '内部公告统计' },
      },
      {
        path: 'competitorStatistics',
        component: () => import('@/views/infoManagement/biddingNotice/competitorStatistics/index'), // Parent router-view
        name: 'CompetitorStatistics',
        meta: { title: '竞品对比统计' },
      },
      {
        path: 'competitorManagement',
        component: () => import('@/views/infoManagement/biddingNotice/competitorManagement/index'), // Parent router-view
        name: 'CompetitorManagement',
        meta: { title: '竞品对比处理' },
      },
      {
        path: 'noticeIdentifyImage',
        component: () => import('@/views/infoManagement/biddingNotice/noticeIdentifyImage/index'), // Parent router-view
        name: 'NoticeIdentifyImage',
        meta: { title: '公告鉴图' },
      },
    ],
  },
  {
    path: '/feijiuData',
    component: Layout,
    meta: {
      title: 'Feijiu数据',
      icon: 'nested',
    },
    redirect: '/feijiuData/assetData',
    children: [
      {
        path: 'assetData',
        component: () => import('@/views/dataAnalysis/feijiuData/assetData/index'), // Parent router-view
        name: 'AssetData',
        meta: { title: '资产数据' },
      },
      {
        path: 'aloneData',
        component: () => import('@/views/dataAnalysis/feijiuData/aloneData/index'), // Parent router-view
        name: 'AloneData',
        meta: { title: '独享数据' },
      },
      {
        path: 'noticeData',
        component: () => import('@/views/dataAnalysis/feijiuData/noticeData/index'), // Parent router-view
        name: 'NoticeData',
        meta: { title: '拍卖数据' },
      },
    ],
  },
  {
    path: '/industryData',
    component: Layout,
    meta: {
      title: '行业数据',
      icon: 'nested',
    },
    redirect: '/industryData/industryAsset',
    children: [
      {
        path: 'industryAsset',
        component: () => import('@/views/dataAnalysis/industryData/industryAsset/index'), // Parent router-view
        name: 'IndustryAsset',
        meta: { title: '行业资产' },
      },
      {
        path: 'industryNotice',
        component: () => import('@/views/dataAnalysis/industryData/industryNotice/index'), // Parent router-view
        name: 'IndustryNotice',
        meta: { title: '行业拍卖' },
      },
    ],
  },
  {
    path: '/usersNumberMenu',
    component: Layout,
    meta: {
      title: '用户量',
      icon: 'nested',
    },
    redirect: '/usersNumberMenu/usersNumber',
    children: [
      {
        path: 'usersNumber',
        component: () => import('@/views/dataAnalysis/usersNumberMenu/usersNumber/index'), // Parent router-view
        name: 'UsersNumber',
        meta: { title: '用户量' },
      },
    ],
  },
  {
    path: '/businessPush',
    component: Layout,
    meta: {
      title: '生意推送',
      icon: 'nested',
    },
    redirect: '/businessPush/assetsPush',
    children: [
      {
        path: 'assetsPush',
        component: () => import('@/views/dataAnalysis/businessPush/assetsPush/index'), // Parent router-view
        name: 'AssetsPush',
        meta: { title: '资产推送' },
      },
      {
        path: 'alonePush',
        component: () => import('@/views/dataAnalysis/businessPush/alonePush/index'), // Parent router-view
        name: 'AlonePush',
        meta: { title: '独享推送' },
      },
      {
        path: 'noticePush',
        component: () => import('@/views/dataAnalysis/businessPush/noticePush/index'), // Parent router-view
        name: 'NoticePush',
        meta: { title: '拍卖推送' },
      },
    ],
  },
  {
    path: '/userProfile',
    component: Layout,
    meta: {
      title: '用户画像',
      icon: 'nested',
    },
    redirect: '/userProfile/groupProfile',
    children: [
      {
        path: 'groupProfile',
        component: () => import('@/views/dataAnalysis/userProfile/groupProfile/index'), // Parent router-view
        name: 'GroupProfile',
        meta: { title: '群体画像' },
      },
      {
        path: 'personProfile',
        component: () => import('@/views/dataAnalysis/userProfile/personProfile/index'), // Parent router-view
        name: 'PersonProfile',
        meta: { title: '个人画像' },
      },
      {
        path: 'labelManagement',
        component: () => import('@/views/dataAnalysis/userProfile/labelManagement/index'), // Parent router-view
        name: 'LabelManagement',
        meta: { title: '标签管理' },
      },
    ],
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true },
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
